package com.bella.api.system.controller;

import com.bella.api.system.dao.model.AuthMenu;
import com.bella.api.system.dto.menu.MenuQueryDto;
import com.bella.api.system.service.MenuService;
import com.bella.api.utils.ApiResponse;
import com.bella.api.utils.ApiResponseCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author zsq
 * @create 2020-05-14-16:04
 */
@Api(description = "角色操作接口")
@RestController
@RequestMapping("/web/v1/menu")
public class MenuController {
    @Autowired
    MenuService menuService;

    @ApiOperation(value = "获取菜单列表", notes = "获取所有菜单列表")
    @RequestMapping(value = "/menuList", method = RequestMethod.GET)
    public ApiResponse menuList(@ModelAttribute MenuQueryDto menuQueryDto) {
        return new ApiResponse(ApiResponseCode.SUCCESS, menuService.getMenuList(menuQueryDto));
    }

    @ApiOperation(value = "菜单详情", notes = "菜单详情")
    @RequestMapping(value = "/menuDetail/{id}", method = RequestMethod.GET)
    public ApiResponse menuDetail(@PathVariable("id") Integer id) {
        return new ApiResponse(ApiResponseCode.SUCCESS, menuService.menuDetail(id));
    }

    @ApiOperation(value = "新增菜单", notes = "新增菜单")
    @RequestMapping(value = "/addMenu", method = RequestMethod.POST)
    public ApiResponse addMenu(@RequestBody AuthMenu authMenu) {
        menuService.addMenu(authMenu);
        return new ApiResponse(ApiResponseCode.SUCCESS);
    }

    @ApiOperation(value = "修改菜单", notes = "修改菜单")
    @RequestMapping(value = "/updMenu", method = RequestMethod.POST)
    public ApiResponse updMenu(@RequestBody AuthMenu authMenu) {
        menuService.updMenu(authMenu);
        return new ApiResponse(ApiResponseCode.SUCCESS);
    }

    @ApiOperation(value = "删除菜单", notes = "删除菜单")
    @RequestMapping(value = "/deleteMenu", method = RequestMethod.POST)
    public ApiResponse deleteMenu(@RequestBody AuthMenu authMenu) {
        menuService.deleteMenu(authMenu);
        return new ApiResponse(ApiResponseCode.SUCCESS);
    }
}
